//
//  DataHandle.m
//  MusicRunner
//
//  Created by Wan on 15/12/9.
//  Copyright © 2015年 WanWanSui. All rights reserved.
//

#import "DataHandle.h"

@implementation DataHandle
+ (instancetype)shareDataHandle {
    static DataHandle *dataHandle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dataHandle = [[DataHandle alloc] init];
    });
    return dataHandle;
}


- (NSString *)getDocumentPath:(NSString *)path {
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [array lastObject];
    NSString *stringPath = [documentPath stringByAppendingPathComponent:@"WanWanSui"];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *NewsPath = [stringPath stringByAppendingPathComponent:path];
    BOOL result = [fileManager createDirectoryAtPath:NewsPath withIntermediateDirectories:YES attributes:nil error:nil];
    if (result) {
        //NSLog(@"缓存成功");
    }
    return NewsPath;
}

- (void)removeFile:(NSString *)file {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL result = [fileManager removeItemAtPath:file error:nil];
    if (result) {
        //NSLog(@"已删除");
    }
}

- (void)removeMyFile {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [array lastObject];
    NSString *stringPath = [documentPath stringByAppendingPathComponent:@"WanWanSui"];
    [fileManager removeItemAtPath:stringPath error:nil];
}

@end
